//
//  FirstBaseViewController.m
//  JJHW_coreData
//
//  Created by lizhenqiang on 16/4/10.
//  Copyright © 2016年 HFKJ_LZQ. All rights reserved.
//

#import "FirstBaseViewController.h"

@interface FirstBaseViewController ()<UITextFieldDelegate>



@end

@implementation FirstBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    // Do any additional setup after loading the view.
    [self setNavBarTitleView];
}

-(void)setNavBarTitleView
{//设置titleview
    _navLabel = [[UITextField alloc] initWithFrame:CGRectMake(30, 0, DeviceWidth-180, 30)];
    _navLabel.enabled = NO;
    _navLabel.backgroundColor = [UIColor clearColor];
    _navLabel.font = themeFont15;
    _navLabel.delegate = self;
    _navLabel.textColor = kDefaultWhiteColor;
//    _navLabel.text = @"请输入关键词";
    _navLabel.placeholder = @"请输入关键词";
    _navLabel.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入关键词" attributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
    _navLabel.keyboardType =UIReturnKeySearch;
//    _clearBtn = [[UIButton alloc] initWithFrame:CGRectMake(DeviceWidth-160, 0, 30, 30)];
//    _clearBtn.hidden = YES;
//    
//    [_clearBtn setImage:[UIImage imageNamed:@"icon_comment"] forState:UIControlStateNormal];
//    [_clearBtn addTarget:self action:@selector(showCityAllBuild:) forControlEvents:UIControlEventTouchUpInside];
//    //    [_navLabel resignFirstResponder];
    self.backImageview = [[UIImageView alloc] initWithFrame:CGRectMake(10, 7, 15, 15)];
    _backImageview.image = [UIImage imageNamed:@"icon_searchsmall"];
    _titleView = [[UIView alloc]initWithFrame:CGRectMake(0, 7, DeviceWidth-150, 30)];//(70, 0, DeviceWidth-130, 30)
//    _clearBtn.frame = CGRectMake(titleView.frame.size.width-33, 0, 30, 30);
    [_titleView addSubview:_backImageview];
    [_titleView addSubview:_navLabel];
//    [titleView addSubview:_clearBtn];
    _titleView.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.4];
    _titleView.layer.borderColor = kDefaultWhiteColor.CGColor;
    _titleView.layer.borderWidth = 1.0;
//    titleView.alpha = 0.6;
    _titleView.layer.cornerRadius = 15.0f;
    _titleView.layer.masksToBounds = YES;
    //    [titleView addSubview:titleImageView];
    self.navigationItem.titleView =_titleView;
    _titleView.userInteractionEnabled = YES;
    UITapGestureRecognizer *singTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gotoSearch)];
    singTap.numberOfTapsRequired = 1;
    [_titleView addGestureRecognizer:singTap];
    self.navigationItem.titleView = _titleView;

}
-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    UIColor * color = NavBarBJColor;
    [self.navigationController.navigationBar lt_setBackgroundColor:[color colorWithAlphaComponent:1.0]];
}
-(void)gotoSearch
{
    CDLog(@"进入搜索页面");
    
}
-(void)setMytitleViewType:(KtitleViewType)type andAlpha:(CGFloat)alpha
{
    UIColor *color = NavBarBJColor;
    switch (type) {
        case KtitleViewTypeNormal: {
            {//有透明度
                
                self.backImageview.image = [UIImage imageNamed:@"icon_search"];
                self.titleView.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.4];
                self.navLabel.backgroundColor = [UIColor clearColor];
                self.navLabel.textColor = kDefaultWhiteColor;
                self.navLabel.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入关键词" attributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
                //            UIColor *mycolor = [UIColor blackColor];
                [self.navigationController.navigationBar lt_setBackgroundColor:[color colorWithAlphaComponent:alpha]];
                self.labelTitleView.text = @"";
            }
            break;
        }
        case KtitleViewTypeUnAlpha: {
            {
               // 没透明
                [self.navigationController.navigationBar lt_setBackgroundColor:[color colorWithAlphaComponent:alpha]];
                self.titleView.backgroundColor = [UIColor whiteColor];
                self.backImageview.image = [UIImage imageNamed:@"icon_search_gray"];
                self.navLabel.backgroundColor = [UIColor whiteColor];
                self.navLabel.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入关键词" attributes:@{NSForegroundColorAttributeName: [UIColor grayColor]}];
                self.navLabel.textColor = kDefaultBlackColor;
            }
            break;
        }
    }
    
}

-(void)setNavBarRightItem
{ //leftItem 让他们在各自VC中去实现
    
}
#pragma mark tableview 代理区
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.pageDataArr.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"common"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"common"];
    }
    cell.textLabel.text = self.pageDataArr[indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

}

#pragma mark textfield 代理区

-(void)textFieldDidBeginEditing:(UITextField *)textField
{

}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self.view endEditing:YES];
    return YES;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
